<template>
    <view class="page">
        <view class="content_top_box">
            <back :isBack="true" :title="'我的钱包'" :isBg="false"></back>

            <view class="touxiang_box">
                <view class="zs_tx_box">
                    <view class="zs_pic_box">
                        <image :src="userInfo.avatar" mode="scaleToFill" />
                    </view>
                    <view class="zs_name_box">
                        {{ userInfo.nickname }}
                    </view>
                </view>
                <view class="tjr_nm_box">
                    推荐人：{{ userInfo.recommend }}
                </view>
            </view>
            <view class="qb_top_box">
                <view class="ziyan_box">
                    <view class="left_zongwall_box">账户总金额(元)</view>
                    <view class="right_leijiwall_box">累计提现(元)</view>
                </view>
                <view class="top_money_box">
                    <view class="left_moner_box">{{ userInfo.total_money }}</view>
                    <view class="rt_moner_box">{{ userInfo.withdraw_money }}</view>
                </view>
            </view>
        </view>

        <scroll-view scroll-y style="height: 900rpx;">
            <!-- 可提现金额 -->

            <view class="withdrawn_box">
                <view class="txjl_box" @click="gojilu">提现记录 <u-icon name="arrow-right" :color="titleIconColor"
                        size="28"></u-icon>
                </view>
                <view class="l_box">
                    <view class="l_t_box">可提现金额(元)</view>
                    <view class="l_b_box">{{ userInfo.balance_money }}</view>
                </view>
                <view class="r_box" @click="goTx">去提现</view>
            </view>

            <view class="cz_big_box">
                <view class="dange_cz_sm_box" v-for="(item, index) in czList" :key="index" @click="czBtn(item)">
                    <view class="dange_cz_sm_top_box">
                        <image :src="item.img_url" mode="scaleToFill" />
                    </view>
                    <view class="dange_cz_sm_bot_box">{{ item.text }}</view>
                </view>
            </view>
            <view class="fxsm_box">
                <image :src="share_img" mode="widthFix" />
            </view>
        </scroll-view>
        <u-popup v-model="tgmShow" mode="center">

            <view class="haibaobox">
                <view class="chahao_box" @click="gbTc"></view>
                <image :src="poster" class="bgimg" :show-menu-by-longpress='true'/>
                <!-- 生成图片 -->
                <poster ref="poster" :list="list" :width="750" :height="1334" @on-success="posterSuccess"
                    @on-error="posterError"></poster>
                <view class="commonBtn">长按图片保存到相册</view>
            </view>
        </u-popup>
    </view>
</template>
<script>
// import { mapState } from 'vuex'
import back from "@/components/goback/goback"
import Poster from '../components/zhangyuhao-poster/Poster'
export default {
    components: {
        back, Poster
    },
    // computed: {
    //     ...mapState([
    //         'userInfo'
    //     ])
    // },
    data() {
        return {
            tgmShow: false,//推广码弹窗
            czList: [
                {
                    id: 1,
                    text: '佣金明细',
                    img_url: 'https://rubbish.lwjcg.com/static/order/yjmx.png',
                    navUrl: '/userPage/commission/commission'
                },
                {
                    id: 2,
                    text: '我的团队',
                    img_url: 'https://rubbish.lwjcg.com/static/order/wdtd.png',
                    navUrl: '/userPage/mySteam/mySteam'
                },
                {
                    id: 3,
                    text: '推广二维码',
                    img_url: 'https://rubbish.lwjcg.com/static/order/tgm.png'
                },
                {
                    id: 4,
                    text: '二级分销商',
                    img_url: 'https://rubbish.lwjcg.com/static/order/ej.png',
                    navUrl: '/userPage/retailstore/retailstore'
                },
            ],
            poster: '',
            list: [],
            uploadImg: '',//保存到手机的图片路径
            imageShow: false,
            shareObj: {},
            userInfo: {},
            qrcode: '',//为1的时候跳二维码
            share_img: ''

        }
    },
    onLoad(e) {
        this.qrcode = e.qrcode
        console.log(e)
        if (this.qrcode == "1") {
            this.getCode()
            this.tgmShow = true
        }
    },
    onShareTimeline() {
        return {
            title: "六久六智运",
            imageUrl: this.poster
        }
    },
    onShow() {
        this.info()


    },

    methods: {
        info() {
            this.$Request.post(this.$api.user.info).then(res => {
                if (res.code == 200) {
                    this.userInfo = res.data
                    this.getRule()
                }

            })
        },
        gojilu() {
            uni.navigateTo({
                url: '/userPage/record/record'
            })
        },
        gbTc() {
            this.tgmShow = false
        },
        goTx() {
            uni.navigateTo({
                url: '/userPage/deposit/deposit?yue=' + this.userInfo.balance_money
            })
        },
        czBtn(item) {
            if (item.id == 3) {
                this.getCode()
                this.tgmShow = true

            } else if (item.id == 4) {
                if (this.userInfo.share_id > 0) {
                    this.$Request.post(this.$api.word.shareApply).then(res => {
                        if (res.code == 200) {
                            uni.showToast({
                                title: '您已是二级分销员',
                                icon: 'none'
                            })
                        } else {
                            uni.navigateTo({
                                url: item.navUrl + '?autoCommit=' + true
                            })
                        }
                    })
                } else {
                    uni.navigateTo({
                        url: item.navUrl
                    })
                }

            }
            else {
                uni.navigateTo({
                    url: item.navUrl
                })
            }
        },
        // rule
        getRule() {
            this.$Request.post(this.$api.word.systemShare_rule).then(res => {
                if (res.code == 200) {
                    this.share_img = res.data.rule_url
                }
            })

        },
        getCode() {
            this.$Request.post(this.$api.user.userGetCode).then(res => {
                if (res.code == 200) {
                    this.shareObj = res.data
                    this.start()
                }
            })
        },
        posterError(err) {
            console.log(err)
        },
        posterSuccess(url) {
            // 生成成功，会把临时路径在这里返回
            this.poster = url;
            console.log(url)
        },
        start() {
            // 赋值需要渲染的信息
            this.list = [{
                type: 'image',
                // path替换成你自己的图片，注意需要在小程序开发设置中配置域名
                path: this.shareObj.share_url,
                x: 0,
                y: 0,
                width: 750,
                height: 1332
            },
            {
                type: 'image',
                path: this.shareObj.qrcode,
                x: 76,
                y: 988,
                width: 250,
                height: 250
            }
            ];
            // 生成图片
            this.$nextTick(() => {
                // 要放在$nextTick()里，不然会空白
                this.$refs.poster.create();
            })
        }



    }
}
</script>
<style lang="scss" scoped>
/deep/.u-mode-center-box {
    background-color: rgba(246, 246, 246, 0) !important;
}

.page {
    width: 100vw;
    height: 100vh;
    background-color: rgba(246, 246, 246, 1);

    .content_top_box {
        width: 100%;
        height: 710rpx;
        background: linear-gradient(180deg, rgba(226, 244, 243, 1) 0%, rgba(231, 245, 228, 0) 100%);

        .touxiang_box {
            width: 100%;
            height: 132rpx;
            box-sizing: border-box;
            padding-left: 30rpx;
            padding-right: 72rpx;
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-top: 40rpx;
            margin-bottom: 60rpx;

            .zs_tx_box {
                width: 50%;
                height: 132rpx;
                display: flex;
                justify-content: flex-start;
                align-items: center;

                .zs_pic_box {
                    width: 132rpx;
                    height: 132rpx;
                    border-radius: 50%;
                    margin-right: 24rpx;

                    image {
                        width: 100%;
                        height: 100%;
                        border-radius: 50%;
                    }
                }

                .zs_name_box {
                    height: 46rpx;
                    font-size: 32rpx;
                    font-weight: 500;
                    line-height: 46rpx;
                    color: rgba(0, 0, 0, 1);

                }
            }

            .tjr_nm_box {
                width: 50%;
                height: 132rpx;
                display: flex;
                justify-content: flex-end;
                font-size: 32rpx;
                font-weight: 500;
                line-height: 132rpx;
                color: rgba(0, 0, 0, 1);

            }
        }

        .qb_top_box {
            width: 704rpx;
            height: 286rpx;
            border-radius: 28rpx;
            background-image: url('https://build.lwjcg.com/uploads/wall_bg.png');
            background-size: 100% 100%;
            margin: auto;
            margin-top: 40rpx;
            margin-bottom: 20rpx;
            box-sizing: border-box;
            padding-top: 72rpx;

            .ziyan_box {
                width: 100%;
                height: 40rpx;
                display: flex;
                justify-content: space-between;
                margin-bottom: 10rpx;

                .left_zongwall_box,
                .right_leijiwall_box {
                    width: 50%;
                    height: 40rpx;
                    line-height: 40rpx;
                    text-align: center;
                    font-size: 28rpx;
                    font-weight: 400;
                    line-height: 40rpx;
                    color: rgba(255, 255, 255, 1);
                }
            }

            .top_money_box {
                width: 100%;
                height: 102rpx;
                display: flex;
                justify-content: space-between;

                .left_moner_box,
                .rt_moner_box {
                    width: 100%;
                    height: 102rpx;
                    line-height: 102rpx;
                    text-align: center;
                    font-size: 72rpx;
                    font-weight: 500;
                    line-height: 102rpx;
                    color: rgba(255, 255, 255, 1);
                }
            }


        }
    }

    .withdrawn_box {
        width: 704rpx;
        height: 190rpx;
        border-radius: 34rpx;
        background: rgba(255, 255, 255, 1);
        margin: auto;
        margin-bottom: 20rpx;
        box-sizing: border-box;
        padding: 40rpx 24rpx 0 38rpx;
        display: flex;
        justify-content: space-between;
        position: relative;

        .txjl_box {
            position: absolute;
            right: 20rpx;
            top: 40rpx;
        }

        .l_box {
            width: 50%;

            .l_t_box {
                height: 40rpx;
                opacity: 1;
                font-size: 28rpx;
                font-weight: 400;
                line-height: 40rpx;
                color: rgba(0, 0, 0, 1);
                margin-bottom: 14rpx;

            }

            .l_b_box {
                height: 68rpx;
                opacity: 1;
                font-size: 48rpx;
                font-weight: 400;
                line-height: 68rpx;
                color: rgba(0, 0, 0, 1);

            }
        }

        .r_box {
            width: 192rpx;
            height: 80rpx;
            border-radius: 14rpx;
            background: rgba(26, 194, 121, 1);
            text-align: center;
            line-height: 80rpx;
            margin-top: 52rpx;
            font-size: 34rpx;
            font-weight: 400;
            color: rgba(255, 255, 255, 1);
        }

    }




    .cz_big_box {
        width: 704rpx;
        height: 190rpx;
        border-radius: 34rpx;
        background: rgba(255, 255, 255, 1);
        margin: auto;
        box-sizing: border-box;
        padding: 0 30rpx;
        display: flex;
        justify-content: space-between;
        align-items: center;
        margin-bottom: 20rpx;

        .dange_cz_sm_box {
            width: 130rpx;
            height: 128rpx;
            // margin-right: 80rpx;

            .dange_cz_sm_top_box {
                width: 80rpx;
                height: 80rpx;
                border-radius: 50%;
                margin: auto;
                margin-bottom: 14rpx;

                image {
                    width: 100%;
                    height: 100%;
                    border-radius: 50%;
                }
            }

            .dange_cz_sm_bot_box {
                width: 100%;
                text-align: center;
                height: 34rpx;
                font-size: 22rpx;
                font-weight: 400;
                line-height: 34rpx;
                color: rgba(0, 0, 0, 1);

            }
        }

    }

    .fxsm_box {
        width: 704rpx;
        // height: 532rpx;
        border-radius: 34rpx;
        margin: auto;

        image {
            width: 100%;
        }

    }
}


.haibaobox {
    width: 100%;
    height: 1240rpx;

    .chahao_box {
        width: 68rpx;
        height: 68rpx;
        background-image: url('https://rubbish.lwjcg.com/static/order/yxh.png');
        background-size: 100% 100%;
        margin-bottom: 32rpx;
        margin-left: 500rpx;

    }

    .bgimg {
        position: relative;
        width: 568rpx;
        height: 900rpx;


    }

    .maimg {
        position: absolute;
        left: 0;
        right: 0;
        margin: auto;
        bottom: 260rpx;
        width: 210rpx;
        height: 210rpx;
        margin: 0 auto;
    }
}

/* 按钮 */
.commonBtn {
    width: 100%;
    height: 80rpx;
    border-radius: 14rpx;
    // background: rgba(255, 255, 255, 1);
    font-size: 36rpx;
    font-weight: 400;
    line-height: 80rpx;
    color: rgba(255, 255, 255, 1);
    text-align: center;
    margin: auto;

}
</style>